import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
import tenantHome from '../components/tenantHome.vue'
import adminHome from '../components/adminHome.vue'
// import answererHome from '../components/answererHome.vue'
import userHome from '../components/userHome.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/Users.vue'
import Rights from '../components/power/Rights.vue'
import Roles from '../components/power/Roles.vue'
import Cate from '../components/questionBank/Cate.vue'
import Params from '../components/questionBank/Params.vue'
import GoodsList from '../components/questionBank/List.vue'
import Add from '../components/questionBank/Add.vue'
import Order from '../components/order/Order.vue'
import Report from '../components/report/Report.vue'
import Question from '../components/questions/Questions.vue'
import CreateQuestion from '../components/questions/createQuestion.vue'
import Group from '../components/groups/group.vue'
import PreviewQuestion from '../components/questions/previewQuestion.vue'
import Sign from '../components/Sign'
import lookForPassword from '../components/lookForPassword'
import Tenant from '../components/tenant/tenant'
import PostQuestion from '../components/postQuestion'
import Answerers from '@/components/answerers/Answerers'
import AnswerQuestion from '@/components/answerQuestion'
import Creategroup from '@/components/groups/creategroup'
import Logins from '../components/Logins'
import LoginByPhone from '../components/LoginByPhone'
import fee from '@/components/tenant/fee'
import NewPreviewQuestion from '../components/questions/newpreviewQuestion'
import ChangeInfo from '@/components/personalInfo/changeInfo'

Vue.use(VueRouter)
const router = new VueRouter({
  routes: [{
    path: '/login',
    component: Logins
  }, {
    path: '/',
    redirect: '/login'
  },
    {
      path: '/LoginByPhone',
      component: LoginByPhone
    },
    {
      path: '/NewQuestion',
      component: NewPreviewQuestion
    },
    {
      path: '/sign',
      component: Sign,
    },
    {
      path: '/postQuestion',
      component: PostQuestion,
    },
    {
      path: '/answerQuestion',
      component: AnswerQuestion,
    },
    {
      path: '/changePassword',
      component: lookForPassword,
    },
    {
      path: '/adminHome',
      component: adminHome,
      children: [
        {
          path: '/tenant',
          component: Tenant,
        },{
          path: '/roles',
          component: Roles
        },{
          path: '/fee',
          component: fee
        },
      ]
    },
    {
      path: '/tenantHome',
      component: tenantHome,
      children: [
        {
          path: '/users',
          component: Users
        }
      ]
    },
    {
      path: '/userHome',
      component: userHome,
      children: [
        {
          path: '/questions',
          component: Question
        },{
          path: '/reports',
          component: Report
        },{
          path: '/questionBank',
          component: GoodsList
        },
        {
          path: '/group',
          component: Group
        },
        {
          path: '/creategroup',
          component: Creategroup
        },
        {
          path: '/createQuestion',
          component: CreateQuestion
        },

        {
          path: '/previewQuestion',
          component: PreviewQuestion
        },
        {
          path: '/answerers',
          component: Answerers
        },
      ]
    },
    {
      path: '/home',
      component: Home,
      //redirect: '/welcome',
      children: [
        {
          path: '/welcome',
          component: Welcome
        },
        {
          path: '/users',
          component: Users
        },
        {
          path: '/rights',
          component: Rights
        },
        {
          path: '/roles',
          component: Roles
        },
        {
          path: '/categories',
          component: Cate
        },
        {
          path: '/params',
          component: Params
        },
        {
          path: '/questionBank',
          component: GoodsList
        },
        {
          path: '/tenant',
          component: Tenant,
        },
        {
          path: '/questionBank/add',
          component: Add
        },
        {
          path: '/orders',
          component: Order
        },
        {
          path: '/reports',
          component: Report
        },
        {
          path: '/questions',
          component: Question
        },
        {
          path: '/group',
          component: Group
        },
        {
          path: '/creategroup',
          component: Creategroup
        },
        {
          path: '/createQuestion',
          component: CreateQuestion
        },

        {
          path: '/previewQuestion',
          component: PreviewQuestion
        },
        {
          path: '/answerers',
          component: Answerers
        },
        {
          path: '/changeInfo',
          component: ChangeInfo
        },
        {
          path: '/fee',
          component: fee
        },
      ]
    }
  ]
})

// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to代表将要访问的路径

  // from代表从哪个路径跳转而来

  // next是一个函数，表示放行
  if (to.path === '/login') {
    return next()
  }
  // 获取token，token不存在就跳转到登陆页面
  // const tokenStr = window.sessionStorage.getItem('token')
  // if (!tokenStr) {
  //     return next('/login')
  // }
  next()
})

export default router
